package com.share.netdisk.config;

import org.apache.hadoop.fs.FileSystem;
import org.springframework.context.annotation.Bean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

@Configuration
public class HdfsConfig {

	@Value("${hdfs.uri}")
	private String hdfsUri;

	@Value("${hdfs.user}")
	private String hdfsUser;

	@Value("${hdfs.block-size}")
	private long blockSize;

	@Bean
	public FileSystem fileSystem() throws URISyntaxException, IOException, InterruptedException {
		//名字和配置类一样，所以使用全名的Configuration来避免冲突
		org.apache.hadoop.conf.Configuration conf = new org.apache.hadoop.conf.Configuration();
		conf.setLong("dfs.blocksize", blockSize);
		conf.set("fs.defaultFS", hdfsUri);
		return FileSystem.get(new URI(hdfsUri), conf, hdfsUser);
	}

}
